package com.study.spring.jvm;

import java.util.ArrayList;
import java.util.List;

/**
 * VM Args: -Xms20m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError
 *
 * @author zhang
 */
public class TestHeap {

    public static void main(String[] args) {
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(100L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        List<OomObject> list = null;
        try {
            list = new ArrayList<>();
            while (true) {
                Thread.sleep(1L);
                list.add(new OomObject());
            }
        } catch (Error | InterruptedException e) {
            e.printStackTrace();
            System.out.println("d昂前抛出的错误信息：{}" + list.size());
        }


    }

    static class OomObject {

        private final Integer i = new Integer(0);

        private final String[] s = new String[10];

    }

}
